using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using ICSharpCode.SharpZipLib;
using ICSharpCode.SharpZipLib.GZip;

namespace KBESerialize
{
    public static class GzipHelper
    {
        private static byte[] data = new byte[1024 * 1024];
        public static byte[] Compress(byte[] src)
        {
            var ms = new MemoryStream();
            var gzip = new GZipOutputStream(ms);

            gzip.Write(src, 0, src.Length);
            gzip.Close();
            return ms.ToArray();
        }

        public static byte[] Decompress(byte[] src)
        {
            Array.Clear(data, 0, data.Length);
            var gzip = new GZipInputStream(new MemoryStream(src));
            var ms = new MemoryStream();
            int count = 0;
            while ((count = gzip.Read(data, 0, data.Length)) != 0)
            {
                ms.Write(data, 0, count);
            }

            return ms.ToArray();
        }
    }
}
